/**
 * 授权 API
 */
import {
	http
} from '../request/main.js';


/**
 * 获取入口数据
 * 
 * @returns {Promise}
 */
export function getEnterInfo(wx_code, auth_key) {
	return http.post('/card/getEnterInfo', {
		wx_code,
		auth_key
	}, {
		onlyCard: true,
		muteLogin: true
	});
}

/**
 * 礼品卡登录 - 卡密
 * 
 * @returns {Promise}
 */
export function loginByCard(number, password, wx_code, auth_key) {
	return http.post('/card/loginByCard', {
		number,
		password,
		wx_code,
		auth_key
	}, {
		onlyCard: true,
		muteLogin: true
	})
}

/**
 * 用户登录 - 手机验证码
 * 
 * @returns {Promise}
 */
export function loginByPhoneCaptcha(phone, captcha, cid, wx_code, auth_key) {
	return http.post('/card/loginByPhoneCaptcha', {
		phone,
		captcha,
		cid,
		wx_code,
		auth_key
	}, {
		muteLogin: true
	})
}

/**
 * 发送手机验证吗
 * 
 * @returns {Promise}
 */
export function sendPhoneCaptcha(phone, cid, wx_code, muteLogin) {
	return http.post('/card/sendPhoneCaptcha', {
		phone,
		cid,
		wx_code
	}, {
		muteLogin: muteLogin
	})
}

/**
 * 礼品卡登录 - 退出
 *
 * @returns {Promise}
 */
export function logout() {
	return http.post('/card/logout', {}, {
		onlyCard: true
	})
}

/**
 * 获取整体数据
 * 
 * @returns {Promise}
 */
export function getWrapData() {
	return http.post('/card/getWrapData', {}, {
		onlyCard: true
	});
}

export function getWrapDataPre(card_pre_key, flag, card_id) {
	return http.post('/preview/getWrapDataPre', {}, {
		onlyCard: false,
		onlyPrev: true,
		card_pre_key,
		flag,
		card_id
	});
}

/**
 * 获取礼品详情
 * 
 * @returns {Promise}
 */
export function getDetail(id) {
	return http.post('/card/getDetail', {
		id
	}, {
		onlyCard: true
	});
}

export function getDetailPre(id, card_pre_key, flag, card_id) {
	return http.post('/preview/getDetailPre', {
	}, {
		onlyCard: false,
		onlyPrev: true,
		id, card_pre_key, flag, card_id
	});
}


/**
 * 获取兑换预览
 * 
 * @returns {Promise}
 */
export function getPreview(gift_id, gift_spec_id) {
	return http.post('/card/getPreview', {
		gift_id,
		gift_spec_id
	}, {
		onlyCard: true
	});
}

/**
 * 进行兑换
 * 
 * @returns {Promise}
 */
export function exchange(formData) {
	return http.post('/card/exchange', formData, {
		onlyCard: true
	});
}


/**
 * 取消订单
 * 
 * @returns {Promise}
 */
export function orderCancel(order_id) {
	return http.post('/card/orderCancel', {
		order_id
	}, {
		onlyCard: true
	});
}



/**
 * 获取兑换列表
 * 
 * @returns {Promise}
 */
export function getOrderList(group, page, page_size) {
	return http.post('/card/getOrderList', {
		group,
		page,
		page_size
	}, {
		onlyCard: true
	});
}

/**
 * 获取兑换详情
 * 
 * @returns {Promise}
 */
export function getOrderDetail(id) {
	return http.post('/card/getOrderDetail', {
		id
	}, {
		onlyCard: true
	});
}

/**
 * 获取物流动态
 * 
 * @returns {Promise}
 */
export function getExpressFeed(id) {
	return http.post('/card/getExpressFeed', {
		id
	}, {
		onlyCard: true
	});
}